#pragma once
# include "RBTree.h"

namespace xx
{
	template<class K, class V>
	class Mymap
	{
	public:
		struct MymapREK
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
		typedef typename RBTree<K,pair<const K,V>,MymapREK>::Iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, MymapREK>::const_Iterator const_iterator;
		iterator begin()
		{
			return _t.begin();
		}
		iterator end()
		{
			return _t.end();
		}
		const_iterator begin() const
		{
			return _t.begin();
		}
		const_iterator end() const
		{
			return _t.end();
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> pp = insert({ key,V() });
			return pp.first->second;
		}

		pair<iterator,bool> insert(const pair<K, V>& kv)
		{
			return _t.insert(kv);
		}
		
	private:
		RBTree<K, pair<const K, V>, MymapREK> _t;
	};

}